﻿using UnityEngine;
using System.Collections.Generic;

public class Benzier : MonoBehaviour {

    public Vector3 _Benzier( List<Vector3> listVector,ref float time,float delay)
    {
        int n = listVector.Count - 1;
        time += delay;
        if (time >= 1) time = 0;
        Vector3 temp = Mathf.Pow((1 - time), n) * listVector[0];

        for (int i = 1; i < n; i++)
        {
            float x = GT(n - (i - 1)) / (GT(n - i) * GT(i));
            float t = Mathf.Pow((1 - time), n - i);

            temp = temp + (x * t * time * listVector[i]);
        }
        temp = temp + (Mathf.Pow(time, n) * listVector[n]);

        return temp;
    }
    public float GT(int n)
    {
        int gt=1;
        for (int i = 1; i <= n; i++)
            gt *= i;

        return gt;
            
    }
    public  void AddList(ref List<Vector3> listVector, Vector3 P0, Vector3 P1, Vector3 P2)
    {
        listVector.Clear();
        listVector.Add(P0);
        listVector.Add(P1);
        listVector.Add(P2);
    }
   public void AddList(ref List<Vector3> listVector, Vector3 P0, Vector3 P1, Vector3 P2, Vector3 P3)
    {
        listVector.Clear();
        listVector.Add(P0);
        listVector.Add(P1);
        listVector.Add(P2);
        listVector.Add(P3);
    }

   public void AddList(ref List<Vector3> listVector, Vector3 P0, Vector3 P1, Vector3 P2, Vector3 P3, Vector3 P4)
    {
        listVector.Clear();
        listVector.Add(P0);
        listVector.Add(P1);
        listVector.Add(P2);
        listVector.Add(P3);
        listVector.Add(P4);
    }
}
